//x个学校，每个学校y个班级，每个班级z个学生，计算每个学校 每个班级的平均成绩及每个学校的平均成绩。

#include<stdio.h>
#include<stdlib.h>
#define X 2
#define Y 2
#define Z 3

typedef struct st
{		
	char *pname;
	int pid;
	int score;
}sStu,*pStu;

typedef struct class
{
	char *cname;
	int cid;
	pStu stu_stu;
}sStuCla,*pStuCla;

typedef struct school
{
	char *sname;
	int sid;
	pStuCla stu_cla;
}sStusch,*pStusch;

void input(pStusch p)
{
	int i,j,k;
	for(i = 0;i < X;i++)
	{
		for(j = 0;j < Y;j++)
		{
			for(k = 0;k < Z;k++)
			{
				(p + k) -> sname=(char *)malloc(sizeof(char) * 20);
				(p + k) -> stu_cla -> cname=(char *)malloc(sizeof(char) * 20);
				(p + k) -> stu_cla -> stu_stu -> pname=(char *)malloc(sizeof(char) * 20);
				scanf("%s %d %s %d %s %d %d",(p + k) -> sname, &(p + k) -> sid, (p + k) -> stu_cla -> cname, & (p + k) -> stu_cla -> cid,(p + k) -> stu_cla -> stu_stu -> pname, &(p + k) -> stu_cla -> stu_stu -> pid, &(p + k) -> stu_cla -> stu_stu -> score);
			}
		}
	}
}

void average_class(pStusch p)
{
	int i,j,k;
	int total_class = 0;
	for(i = 0;i < X;i++)
	{
		for(j = 0;j < Y;j++)
		{
			for(k = 0;k < Z;k++)
			{
				total_class = total_class + (p + k) -> stu_cla -> stu_stu -> score;
			}
	 		printf("the average of number %d class is :%d.\n",j,total_class / Y);
		}
		printf("the average of number %d school is :%d.\n",i,total_class / Y / X);
	}
}

int main ()
{

	int i,j,k;
	sStusch sch[X];
	pStusch p = sch;
        input( p );
        average( p );
	return 0;
}
